﻿@addTagHelper *, WebVella.Erp.Plugins.Core
@addTagHelper *, WebVella.Erp.Web
@addTagHelper *, WebVella.TagHelpers
@using WebVella.Erp.Web.Utils;
@using WebVella.Erp.Web.Components;
@using WebVella.Erp.Web.Models;
@using WebVella.TagHelpers.Models;
@{
	var options = (PcFieldMultiSelect.PcFieldMultiSelectOptions)ViewBag.Options;
	var node = (PageBodyNode)ViewBag.Node;
	var fieldModel = (PcFieldMultiSelect.PcFieldMultiSelectModel)ViewBag.Model;
	var labelMode = (WvLabelRenderMode)ViewBag.LabelMode;
	var mode = (WvFieldRenderMode)ViewBag.Mode;
	if(String.IsNullOrWhiteSpace(fieldModel.ApiUrl))
		fieldModel.ApiUrl = $"/api/v3/en_US/record/{fieldModel.EntityName}/{fieldModel.RecordId}";

	var placeholder = "";
	if(!String.IsNullOrWhiteSpace(options.Placeholder))
		placeholder = options.Placeholder;
	else if(!String.IsNullOrWhiteSpace(fieldModel.Placeholder))
		placeholder = fieldModel.Placeholder;
}
<div class="p-1">
	<wv-field-multiselect label-mode="@labelMode" label-text="@options.LabelText" label-warning-text="@fieldModel.LabelWarningText"
						  label-error-text="@fieldModel.LabelErrorText" label-help-text="@options.LabelHelpText" field-id="@fieldModel.FieldId"
						  name="@options.Name" class="@options.Class" value="@fieldModel.Value" mode="@mode" access="@fieldModel.Access"
						  init-errors="@fieldModel.InitErrors" validation-errors="@fieldModel.ValidationErrors.ToKeyValuePair()" 
						  api-url="@fieldModel.ApiUrl" access-denied-message="@fieldModel.AccessDeniedMessage"
						  empty-value-message="@fieldModel.EmptyValueMessage" required="@fieldModel.Required" placeholder="@placeholder"
						  description="@options.Description" locale="@fieldModel.Locale" 
						  options="@fieldModel.Options.ToWvSelectOption()"  select-match-type="@options.SelectMatchingType">
	@if (options.ShowIcon)
	{
		<wv-field-prepend><span class='input-group-text'><i class='fa fa-fw fa-indent'></i></span></wv-field-prepend>
	}
	</wv-field-multiselect>
</div>